package com.dinggou.shopjb.view;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.TextView;

import com.dinggou.shopjb.R;
import com.dinggou.shopjb.activitys.MainActivity;
import com.dinggou.shopjb.base.BaseActivity;
import com.dinggou.shopjb.bean.CreateOrderResultBean;
import com.dinggou.shopjb.utils.RouteUtil;
import com.dinggou.shopjb.utils.Utils;


public class OrderSuccessDialog extends MyDialog implements View.OnClickListener {

    private View rootView;
    private View view_top;
    private TextView tv_integral;
    private TextView tv_cancel;
    private TextView tv_submit;
    private ImageView iv_tips;

    public OrderSuccessDialog(Context context) {
        this(context, false, Gravity.BOTTOM);
    }

    public OrderSuccessDialog(Context context, boolean isCancelAble, int gravity) {
        super(context, isCancelAble, gravity);
        Window w = this.getWindow();
        if (w != null) {
            w.setWindowAnimations(R.style.dialogTranslateAnim);
        }
        rootView = LayoutInflater.from(context).inflate(R.layout.dialog_order_success, null);
        setContentView(rootView);

        view_top = rootView.findViewById(R.id.view_top);
        tv_integral = rootView.findViewById(R.id.tv_integral);
        tv_cancel = rootView.findViewById(R.id.tv_cancel);
        tv_submit = rootView.findViewById(R.id.tv_submit);
        iv_tips = rootView.findViewById(R.id.iv_tips);

        tv_cancel.setOnClickListener(this);
        tv_submit.setOnClickListener(this);
        view_top.setOnClickListener(this);
        iv_tips.setOnClickListener(this);
    }

    public void init(CreateOrderResultBean bean) {
        String integral;
        integral = "下单成功！获得<font color=\"#C99C50\">" + bean.integral + "积分</font>";
        tv_cancel.setVisibility(View.VISIBLE);
        tv_submit.setText("继续下单");
        Utils.setHtmlText(tv_integral, integral);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.view_top:
                if (isCancelAble) {
                    dismiss();
                }
                break;
            case R.id.tv_cancel:
                RouteUtil.toMainActivity((BaseActivity) mContext, MainActivity.TAB_ORDER);
                dismiss();
                break;
            case R.id.tv_submit:
                dismiss();
                break;
            case R.id.iv_tips:
                RouteUtil.toMainActivity((BaseActivity) mContext, MainActivity.TAB_WELFATE);
                dismiss();
                break;
        }
    }


}

